<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of BAParseTextUtil
 *
 * @author jianfeng
 */
class BParseTextUtil {

    //put your code here
    const Todo_Remove_Capital_Prefix_And_Specific_Surfix = 'remove_capital_prefix_and_specific_surfix';

    public static function parseText($todo, $text, $params = NULL) {

        if ($todo == self::Todo_Remove_Capital_Prefix_And_Specific_Surfix) {
            $matches = array();
            $pattern = "/^([A-Z]+)/";
            preg_match($pattern, $text, $matches);
            $capitalPrefix = $matches[0];
            $refinedCapitalPrefix = substr($capitalPrefix, 0, -1);
            $pattern2 = "/^(" . $refinedCapitalPrefix . ")/";
            $refinedText = preg_replace($pattern2, '', $text);
            if (is_array($params) && $params != NULL) {
                if (isset($params['surfix'])) {
                    $surfix = $params['surfix'];
                    $pattern3 = "/(" . $surfix . ")$/";
                    $refinedText = preg_replace($pattern3, '', $refinedText);
                }
            }
            return lcfirst($refinedText);
        }

        return FALSE;
    }

}
